package com.shop.user.api.controller;

import com.shop.common.model.InputBean;
import com.shop.common.model.param.user.MessageInput;
import com.shop.common.tmpl.BaseController;
import com.shop.common.util.DateUtil;
import com.shop.common.util.SessionUtils;
import com.shop.common.util.excption.UserNotFoundException;
import com.shop.user.api.api.IMessageApi;
import com.shop.user.api.service.IMessageSvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description:
 *
 * @author zhoulk
 * @date: 2019年05月09日  0:45
 */
@RestController
public class MessageApi extends BaseController implements IMessageApi {

    @Autowired
    IMessageSvc messageSvc;
    @Autowired
    SessionUtils sessionUtils;

    @Override
    public String qryMessaes(MessageInput messageInput,Integer index, Integer pageSize, HttpServletRequest request) throws UserNotFoundException {
        Integer userId = sessionUtils.USER_ID(request);
        messageInput.setAcceptId(userId);
        InputBean<MessageInput> inputBean = new InputBean<>(messageInput);
        inputBean.setIndex(index);
        inputBean.setPageSize(pageSize);
        return returnSvc(messageSvc.qryMsgList4P(inputBean));
    }

    @Override
    public String redMessage(Integer messageId, HttpServletRequest request) throws UserNotFoundException {
        Integer userId = sessionUtils.USER_ID(request);
        MessageInput messageInput = new MessageInput();
        messageInput.setId(messageId);
        messageInput.setAcceptId(userId);
        messageInput.setReadTime(DateUtil.newNowDate());
        messageInput.setMsgStatus(1);
        return returnSvc(messageSvc.modMsg(messageInput));
    }

    @Override
    public String delMessage(Integer messageId, HttpServletRequest request) throws UserNotFoundException {
        Integer userId = sessionUtils.USER_ID(request);
        return returnSvc(messageSvc.delMsg(userId,messageId));
    }


}
